from flask import request
from SQLOperation.UserSQLOperation import UserSQLOperation
from SQLConfig import app


@app.route('/register', methods=['Get', 'POST'])
def register():  # put application's code here
    """
    用户注册
    """
    # 判断用户是否存在
    username = request.json.get("username")
    user = UserSQLOperation.searchByUsername(username)
    if user is not None:
        return "user exist"

    password = request.json.get("password")
    phone = request.json.get("phone")
    email = request.json.get("email")
    name = request.json.get("name")
    gender = request.json.get("gender")
    region = request.json.get("region")
    introduction = request.json.get("introduction")

    UserSQLOperation.insert(username, password, phone, email, name, gender, region, introduction)
    return "OK"
